package com.company.Lab3;

import java.util.Scanner;

public class GlobalUtilityMethod {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double[][] mainMatrix;
        double[][] utilityMatrix;
        double[][] globalUtilityMatrix;
        double[] utilityGlobalSum;
        double[] maxValuesOnColumn;
        double[] minValuesOnColumn;
        double[] probability;
        String[] priority;
        double finalValue;
        int r, c;

        System.out.print("Introduceti numarul de randuri : ");
        r = scanner.nextInt();
        System.out.print("Introduceti numarul de coloane : ");
        c = scanner.nextInt();
//        init arrays
        mainMatrix = new double[r][c];
        utilityMatrix = new double[r][c];
        globalUtilityMatrix = new double[r][c];
        utilityGlobalSum = new double[r];
        maxValuesOnColumn = new double[c];
        minValuesOnColumn = new double[c];
        probability = new double[c];
        priority = new String[c];
//        read arrays from keyboard
        System.out.println("Introduceti matricea generala : ");
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print("[" + i + "][" + j + "] : ");
                mainMatrix[i][j] = scanner.nextDouble();
            }
        }
//        read priority
        System.out.println("Introduceti prioritatile :  (max sau min valori)");
        for (int i = 0; i < c; i++) {
            System.out.print("Prioritatea [" + i + "] : ");
            if (i == 0) {
                scanner.nextLine();
            }
            priority[i] = scanner.nextLine();
        }
//        read probability
        System.out.println("Introduceti probabilitatile : ");
        for (int i = 0; i < c; i++) {
            System.out.print("Probabilitatea[" + i + "] : ");
            probability[i] = scanner.nextDouble();
        }
//          Logic : 1. calc utility matrix
//                  2. calc global utility
//        We would use the same methods that in Aditive method because part of logic are the same
        maxValuesOnColumn = AditiveMethod.calcMaxOnColumn(mainMatrix, r, c);
        minValuesOnColumn = AditiveMethod.calcMinOnColumn(mainMatrix, r, c);
        utilityMatrix = AditiveMethod.calcUtilityMatrix(mainMatrix, maxValuesOnColumn, minValuesOnColumn, priority, r, c);
//        calc global utility
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                globalUtilityMatrix[i][j] = utilityMatrix[i][j] * probability[j];
            }
        }
        utilityGlobalSum = AditiveMethod.calcSumForRowBidimensional(globalUtilityMatrix, r, c);
        finalValue = AditiveMethod.calcMaxForRow(utilityGlobalSum, r);
        System.out.println("Decizia optima : " + finalValue);
    }
}